import 'package:cbec_app/components/base/base_chekbox.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/pages/my/controller/after_pop_ctr.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

//退换货原因弹窗
class RefundReasonPopup extends StatefulWidget {
  RefundReasonPopup({super.key});

  @override
  State<RefundReasonPopup> createState() => _RefundReasonPopupState();
}

class _RefundReasonPopupState extends State<RefundReasonPopup> {
  final AfterPopController afterPopCtr = Get.put(AfterPopController());

  int current = 0;

  @override
  Widget build(BuildContext context) {
    // List reasonList = [
    //   "七天无理由",
    //   "商品与页面描述不符",
    //   "价格变化",
    //   "少件/发错货/未收到货",
    //   "商品质量/故障",
    //   "商品破损/包装问题"
    // ];

    return Container(
      padding: EdgeInsets.all(18.w),
      decoration: border_radis(Colors.white),
      child: Column(
        children: [
          Container(
            alignment: Alignment.center,
            child: Text("申请原因", style: setTextStyle(15, FontWeight.w500, Tools.fromHex("#333333"))),
          ),
          SizedBox(height: 22.w),
          Expanded(
            child: ListView.builder(
              shrinkWrap: true,
              itemCount: afterPopCtr.reasonList.length,
              itemBuilder: (context, index) {
                return reasonItem(afterPopCtr.reasonList[index]['label'], index);
              },
            ),
          ),
          SizedBox(height: 20.h),
          solidButton("确认", () {
            afterPopCtr.choiseReason(afterPopCtr.reasonList[current]['value'], afterPopCtr.reasonList[current]['label']);
          }),
        ],
      ),
    );
  }

  Widget reasonItem(String txt, int index) {
    return BaseInteractive(
      // onClick: () => {
      //   setState(() {
      //     current = index;
      //   })
      // },
      childWidget: Container(
        margin: EdgeInsets.only(bottom: 10.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(txt, style: setTextStyle(12, FontWeight.w500, Tools.fromHex("#333333"))),
            BaseCheckBox(
              value: current == index ? true : false,
              onChange: (v) {
                setState(() {
                  current = index;
                });
              },
            )
          ],
        ),
      ),
    );
  }
}

void refundReasonPopup(context) {
  showModalBottomSheet(
    context: context,
    builder: (BuildContext context) {
      return RefundReasonPopup();
    },
  );
}
